package com.block.api.controller.member;


import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSONObject;
import com.block.datapush.special.service.IMatchUpdateStartLeveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.Charset;
import java.util.Map;

@RestController
@RequestMapping("merchant/callback")
public class MerchantCallbackController {

    @Autowired
    IMatchUpdateStartLeveService matchUpdateStartLeveService;

    /**
     * 用户星级回传
     */
    @RequestMapping(value = "/return/startlevel/{infoId}", method = {RequestMethod.POST})
    public String updateStartLevel(HttpServletRequest request,
                                   @PathVariable("infoId") Integer infoId) {
        try {
            Map<String, String[]> parameterMap = request.getParameterMap();
            String paramContent = IoUtil.read(request.getInputStream(), Charset.defaultCharset());
            JSONObject returnObject = matchUpdateStartLeveService.update(infoId, parameterMap, paramContent);

            return returnObject.toJSONString();
        }catch (Exception exception){
            exception.printStackTrace();
        }

        return "星级回传异常";
    }


}
